package com.zwp.common

import android.util.Log
import android.widget.Toast
import androidx.lifecycle.viewModelScope
import androidx.recyclerview.widget.DiffUtil
import com.zwp.base.base.BaseListViewModel
import com.zwp.base.binding.BindingAction
import com.zwp.base.binding.BindingCommand
import com.zwp.base.paging.CommonFooterAdapter
import com.zwp.common.repository.WanRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
import me.tatarka.bindingcollectionadapter2.ItemBinding
import javax.inject.Inject

@HiltViewModel
class MainViewModel @Inject constructor(
    private val repository: WanRepository,
) : BaseListViewModel<ItemData>() {


    override val itemBinding = ItemBinding.of<ItemData> { itemBinding, position, item ->
        itemBinding.set(BR.viewModel, R.layout.item_text)
    }


    override val diffCallback = object : DiffUtil.ItemCallback<ItemData>() {

        override fun areItemsTheSame(oldItem: ItemData, newItem: ItemData): Boolean =
            oldItem.content == newItem.content

        override fun areContentsTheSame(oldItem: ItemData, newItem: ItemData): Boolean =
            oldItem.content == newItem.content

    }

    val footerAdapter = CommonFooterAdapter()

    fun loadData() =
        paging {
            repository.getArticles(it).data?.datas?.map {
                ItemData(it.title)
            } ?: listOf()
        }

    val testClickCommad = BindingCommand<BindingAction>({
        uc.showDialogEvent.postValue("hhhhhh")
    })



}